﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Electronic_work_order.Interfacess.OA_Organization;
using Electronic_work_order.Model;
namespace Electronic_work_order.Controllers
{
    [ApiController]
    public class OA_OraganizationController : ControllerBase
    {
        private readonly InterFace_Organization _Organization;

        public OA_OraganizationController(InterFace_Organization Organization)
        {
            _Organization = Organization;
        }


        [HttpGet]
        [Route("[controller]/GetOrganizations")]
        //查询的是部门和部门下的所有职位
        public IEnumerable<Organization> GetOrganizations()
        {
          return  _Organization.GetOrganizations();

        }
        [HttpGet]
        [Route("[controller]/GetPosition")]
        //根据ID查询部门有什么职位并有什么人
        public IEnumerable<Position> GetPosition(int ParentId)
        {
           return _Organization.GetPosition(ParentId);
        }
        [HttpGet]
        [Route("[controller]/GetUsers")]
        //查询所有人员并查询其职位
        public IEnumerable<Users> GetUsers()
        {
            return _Organization.GetUsers();
        }
        [HttpPost]
        [Route("[controller]/AddPosition")]
        //添加部门
        public int AddPosition(Organization organization)
        {
           int count= _Organization.AddPosition(organization);
            if (count>0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        [Route("[controller]/GetOrganizationName")]
        //查询所有部门
        public IEnumerable<Organization> GetOrganizationName()
        {
           return _Organization.GetOrganizationName();
        }
        [HttpPost]
        [Route("[controller]/AddDepartment")]
        //添加职位
        public int AddDepartment(Position position)
        {
            if (_Organization.AddDepartment(position)>0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        [Route("[controller]/GetOrageUserName")]
        //查询部门和职位
        public IEnumerable<object> GetOrageUserName(int OrganizationID)
        {
            return _Organization.GetOrageUserName(OrganizationID);
        }

    }
   
    }
